import ReactDOM from "react-dom/client";
import ToastConainer from "./compoents/ToastConainer";
let div = document.getElementById('toast-root-container')
if (!div) {
    div = document.createElement('div');
    div.id = 'toast-root-container';
    document.body.append(div)
}
let root: ReactDOM.Root;
if (div) {
    root = ReactDOM.createRoot(div)
}

let id = 0;

export default function toast(text: string, type: ToastType = 'success') {
    ++id;
    // 每次调用这个函数，就希望创建一个 ToastItem 组件，添加到结构中
    root.render(<ToastConainer data={{ id, text, type }} key="toast-contanier" />)
}